/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */
package cn.com.ksplatform.install.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.ksplatform.base.Return;
import cn.com.ksplatform.base.SimpleReturn;
import cn.com.ksplatform.common.logger.Log;
import cn.com.ksplatform.core.context.PlatformContext;
import cn.com.ksplatform.install.model.InstallInfo;
import cn.com.ksplatform.install.service.IInstallService;

@Controller
@RequestMapping("install")
public class InstallController {
	@Autowired
	@Qualifier("system.core.InstallService")
	private IInstallService installService;
	/**
	 * 测试数据库链接
	 */
	@RequestMapping("testconn")
	@ResponseBody
	public Return testConn(InstallInfo info){
		try {
			installService.testConn(info);
		} catch (Exception e) {
			e.printStackTrace();
			Log.error(e.getMessage());
			return SimpleReturn.error("链接失败!",e.getMessage());
		}
		return SimpleReturn.success("链接成功!");
	}
	
	/**
	 * 测试数据库链接
	 */
	@RequestMapping("doInstall")
	@ResponseBody
	public Return doInstall(InstallInfo info,HttpServletRequest request){
		try {
			installService.doInstall(info,PlatformContext.CONTEXT_PATH);
		} catch (Exception e) {
			Log.error(e);
			e.printStackTrace();
			return SimpleReturn.error("安装失败",e.getMessage());
		}
		return SimpleReturn.success("安装成功,请重新启动应用!");
	}
}
